home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / berndspd / devtools / intuigen / examples / gtcardfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-22  |  8.7 KB  |  597 lines

  1. ;/*
  2. cc GTCardFile.c GTRequest.c -o CTCardFile
  3. stop
  4. */
  5.  
  6. #include <stddef.h>
  7. #include <stdlib.h>
  8. #include <exec/exec.h>       /* These two files are system includes */
  9. #include <intuition/intuition.h>
  10. #include <libraries/GadTools.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <IntuiGen/IntuiGen.h>
  13. #include <IntuiGen/GTRequest.h>
  14.  
  15. APTR IntuitionBase,GfxBase,GadToolsBase;
  16.  
  17. struct Person {
  18.     struct Person *Next,*Prev;
  19.     UBYTE       Name[100],
  20.            Address[100],
  21.            CityStateZip[100],
  22.            Phone[13];
  23. };
  24.  
  25. /* struct Person is the data struct that will store the information typed
  26.     into each card */
  27.  
  28. struct Remember *CardKey=0;
  29.  
  30. struct Person CardBase,*OnScreen=0;
  31.  
  32. /* The preceding variable declarations are for management of the linked list
  33.     used to store data, memory allocation.
  34. */
  35.  
  36.  
  37. /* Inserted 34 lines of code above */
  38. /* The following is IntuiGen generated */
  39.  
  40. struct TextAttr TextAttributes0 =
  41. {
  42.     "topaz.font",
  43.     TOPAZ_EIGHTY,
  44.     NULL,
  45.     FPF_ROMFONT
  46. };
  47.  
  48. struct TagItem QuitGadTags[]=
  49. {
  50.     {  GT_Underscore,'_'  },
  51.     {  TAG_DONE,0  }
  52. };
  53.  
  54. struct NewGadget NewQuitGad=
  55. {
  56.     313,95,
  57.     84,13,
  58.     (UBYTE *)"_Quit",
  59.     &TextAttributes0,
  60.     3,
  61.     0,
  62.     0,
  63.     0
  64. };
  65.  
  66. struct MessageHandler QuitGadEndFillGadgetUp =
  67. {
  68.     NULL,
  69.     "EndFillGadgetUp",
  70.     NULL,
  71.     NULL
  72. };
  73.  
  74. struct GTControl QuitGad =
  75. {
  76.     NULL,
  77.     BUTTON_KIND,
  78.     INITFROMDATA | STOREDATA,
  79.     QuitGadTags,
  80.     NULL,
  81.     &NewQuitGad,
  82.     NULL,
  83.     &QuitGadEndFillGadgetUp,
  84.     'q',
  85.     0,
  86.     0,
  87.     0,0,
  88.     NULL,
  89.     NULL,
  90.     NULL,
  91.     0,0,
  92.     0,
  93.     0,
  94.     NULL,
  95.     NULL,
  96.     NULL,
  97.     NULL,
  98.     NULL,
  99.     NULL,
  100.     NULL
  101. };
  102.  
  103. struct TagItem PreviousGadTags[]=
  104. {
  105.     {  GT_Underscore,'_'  },
  106.     {  TAG_DONE,0  }
  107. };
  108.  
  109. struct NewGadget NewPreviousGad=
  110. {
  111.     228,95,
  112.     84,13,
  113.     (UBYTE *)"_Previous",
  114.     &TextAttributes0,
  115.     2,
  116.     0,
  117.     0,
  118.     0
  119. };
  120.  
  121. struct MessageHandler PreviousGadEndFillGadgetUp =
  122. {
  123.     NULL,
  124.     "EndFillGadgetUp",
  125.     NULL,
  126.     NULL
  127. };
  128.  
  129. struct GTControl PreviousGad =
  130. {
  131.     &QuitGad,
  132.     BUTTON_KIND,
  133.     INITFROMDATA | STOREDATA,
  134.     PreviousGadTags,
  135.     NULL,
  136.     &NewPreviousGad,
  137.     NULL,
  138.     &PreviousGadEndFillGadgetUp,
  139.     'p',
  140.     0,
  141.     0,
  142.     0,0,
  143.     NULL,
  144.     NULL,
  145.     NULL,
  146.     0,0,
  147.     0,
  148.     0,
  149.     NULL,
  150.     NULL,
  151.     NULL,
  152.     NULL,
  153.     NULL,
  154.     NULL,
  155.     NULL
  156. };
  157.  
  158. struct TagItem NextGadTags[]=
  159. {
  160.     {  GT_Underscore,'_'  },
  161.     {  TAG_DONE,0  }
  162. };
  163.  
  164. struct NewGadget NewNextGad=
  165. {
  166.     143,95,
  167.     84,13,
  168.     (UBYTE *)"Ne_xt",
  169.     &TextAttributes0,
  170.     1,
  171.     0,
  172.     0,
  173.     0
  174. };
  175.  
  176. struct MessageHandler NextGadEndFillGadgetUp =
  177. {
  178.     NULL,
  179.     "EndFillGadgetUp",
  180.     NULL,
  181.     NULL
  182. };
  183.  
  184. struct GTControl NextGad =
  185. {
  186.     &PreviousGad,
  187.     BUTTON_KIND,
  188.     INITFROMDATA | STOREDATA,
  189.     NextGadTags,
  190.     NULL,
  191.     &NewNextGad,
  192.     NULL,
  193.     &NextGadEndFillGadgetUp,
  194.     'x',
  195.     0,
  196.     0,
  197.     0,0,
  198.     NULL,
  199.     NULL,
  200.     NULL,
  201.     0,0,
  202.     0,
  203.     0,
  204.     NULL,
  205.     NULL,
  206.     NULL,
  207.     NULL,
  208.     NULL,
  209.     NULL,
  210.     NULL
  211. };
  212.  
  213. struct TagItem NewGadTags[]=
  214. {
  215.     {  GT_Underscore,'_'  },
  216.     {  TAG_DONE,0  }
  217. };
  218.  
  219. struct NewGadget NewNewGad=
  220. {
  221.     58,95,
  222.     84,13,
  223.     (UBYTE *)"Ne_w",
  224.     &TextAttributes0,
  225.     0,
  226.     0,
  227.     0,
  228.     0
  229. };
  230.  
  231. struct MessageHandler NewGadEndFillGadgetUp =
  232. {
  233.     NULL,
  234.     "EndFillGadgetUp",
  235.     NULL,
  236.     NULL
  237. };
  238.  
  239. struct GTControl NewGad =
  240. {
  241.     &NextGad,
  242.     BUTTON_KIND,
  243.     INITFROMDATA | STOREDATA,
  244.     NewGadTags,
  245.     NULL,
  246.     &NewNewGad,
  247.     NULL,
  248.     &NewGadEndFillGadgetUp,
  249.     'w',
  250.     0,
  251.     0,
  252.     0,0,
  253.     NULL,
  254.     NULL,
  255.     NULL,
  256.     0,0,
  257.     0,
  258.     0,
  259.     NULL,
  260.     NULL,
  261.     NULL,
  262.     NULL,
  263.     NULL,
  264.     NULL,
  265.     NULL
  266. };
  267.  
  268. struct TagItem PhoneGadTags[]=
  269. {
  270.     {  GT_Underscore,'_'  },
  271.     {  GA_Immediate,1  },
  272.     {  GTST_MaxChars,50  },
  273.     {  STRINGA_Justification,GACT_STRINGLEFT  },
  274.     {  TAG_DONE,0  }
  275. };
  276.  
  277. struct NewGadget NewPhoneGad=
  278. {
  279.     150,68,
  280.     192,14,
  281.     (UBYTE *)"P_hone",
  282.     &TextAttributes0,
  283.     3,
  284.     0,
  285.     0,
  286.     0
  287. };
  288.  
  289. struct GTControl PhoneGad =
  290. {
  291.     &NewGad,
  292.     STRING_KIND,
  293.     INITFROMDATA | STOREDATA,
  294.     PhoneGadTags,
  295.     NULL,
  296.     &NewPhoneGad,
  297.     NULL,
  298.     NULL,
  299.     'h',
  300.     0,
  301.     0,
  302.     0,0,
  303.     NULL,
  304.     offsetof(struct Person,Phone),
  305.     FLD_STRINGINSTRUCT,
  306.     50,0,
  307.     0,
  308.     0,
  309.     GTST_String,
  310.     NULL,
  311.     NULL,
  312.     NULL,
  313.     NULL,
  314.     NULL,
  315.     NULL
  316. };
  317.  
  318. struct TagItem CityStateZipGadTags[]=
  319. {
  320.     {  GT_Underscore,'_'  },
  321.     {  GA_Immediate,1  },
  322.     {  GTST_MaxChars,50  },
  323.     {  STRINGA_Justification,GACT_STRINGLEFT  },
  324.     {  TAG_DONE,0  }
  325. };
  326.  
  327. struct NewGadget NewCityStateZipGad=
  328. {
  329.     150,53,
  330.     192,14,
  331.     (UBYTE *)"_City, State, Zip",
  332.     &TextAttributes0,
  333.     2,
  334.     0,
  335.     0,
  336.     0
  337. };
  338.  
  339. struct GTControl CityStateZipGad =
  340. {
  341.     &PhoneGad,
  342.     STRING_KIND,
  343.     INITFROMDATA | STOREDATA,
  344.     CityStateZipGadTags,
  345.     NULL,
  346.     &NewCityStateZipGad,
  347.     NULL,
  348.     NULL,
  349.     'c',
  350.     0,
  351.     0,
  352.     0,0,
  353.     NULL,
  354.     offsetof(struct Person,CityStateZip),
  355.     FLD_STRINGINSTRUCT,
  356.     50,0,
  357.     0,
  358.     0,
  359.     GTST_String,
  360.     NULL,
  361.     NULL,
  362.     NULL,
  363.     NULL,
  364.     NULL,
  365.     NULL
  366. };
  367.  
  368. struct TagItem AddressGadTags[]=
  369. {
  370.     {  GT_Underscore,'_'  },
  371.     {  GA_Immediate,1  },
  372.     {  GTST_MaxChars,50  },
  373.     {  STRINGA_Justification,GACT_STRINGLEFT  },
  374.     {  TAG_DONE,0  }
  375. };
  376.  
  377. struct NewGadget NewAddressGad=
  378. {
  379.     150,38,
  380.     192,14,
  381.     (UBYTE *)"_Address",
  382.     &TextAttributes0,
  383.     1,
  384.     0,
  385.     0,
  386.     0
  387. };
  388.  
  389. struct GTControl AddressGad =
  390. {
  391.     &CityStateZipGad,
  392.     STRING_KIND,
  393.     INITFROMDATA | STOREDATA,
  394.     AddressGadTags,
  395.     NULL,
  396.     &NewAddressGad,
  397.     NULL,
  398.     NULL,
  399.     'a',
  400.     0,
  401.     0,
  402.     0,0,
  403.     NULL,
  404.     offsetof(struct Person,Address),
  405.     FLD_STRINGINSTRUCT,
  406.     50,0,
  407.     0,
  408.     0,
  409.     GTST_String,
  410.     NULL,
  411.     NULL,
  412.     NULL,
  413.     NULL,
  414.     NULL,
  415.     NULL
  416. };
  417.  
  418. struct TagItem NameGadTags[]=
  419. {
  420.     {  GT_Underscore,'_'  },
  421.     {  GA_Immediate,1  },
  422.     {  GTST_MaxChars,50  },
  423.     {  STRINGA_Justification,GACT_STRINGLEFT  },
  424.     {  TAG_DONE,0  }
  425. };
  426.  
  427. struct NewGadget NewNameGad=
  428. {
  429.     150,23,
  430.     192,14,
  431.     (UBYTE *)"_Name",
  432.     &TextAttributes0,
  433.     0,
  434.     0,
  435.     0,
  436.     0
  437. };
  438.  
  439. struct GTControl NameGad =
  440. {
  441.     &AddressGad,
  442.     STRING_KIND,
  443.     INITFROMDATA | STOREDATA,
  444.     NameGadTags,
  445.     NULL,
  446.     &NewNameGad,
  447.     NULL,
  448.     NULL,
  449.     'n',
  450.     0,
  451.     0,
  452.     0,0,
  453.     NULL,
  454.     offsetof(struct Person,Name),
  455.     FLD_STRINGINSTRUCT,
  456.     50,0,
  457.     0,
  458.     0,
  459.     GTST_String,
  460.     NULL,
  461.     NULL,
  462.     NULL,
  463.     NULL,
  464.     NULL,
  465.     NULL
  466. };
  467.  
  468. struct TagItem NewCardFileTags[]=
  469. {
  470.     {  WA_Left, 112  },
  471.     {  WA_Top, 89  },
  472.     {  WA_InnerWidth, 414  },
  473.     {  WA_InnerHeight, 111    },
  474.     {  WA_IDCMP,
  475.         IDCMP_GADGETUP | IDCMP_RAWKEY  },
  476.     {  WA_Title, "IntuiGen Card File"  },
  477.     {  WA_MinWidth, 420  },
  478.     {  WA_MinHeight, 124  },
  479.     {  WA_MaxWidth, 420  },
  480.     {  WA_MaxHeight, 124  },
  481.     {  WA_AutoAdjust, 1  },
  482.     {  WA_Flags,
  483.         WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE  }
  484. };
  485.  
  486.  
  487. struct GTRequest CardRequest =
  488. {
  489.     NewCardFileTags,
  490.     NULL,
  491.     NULL,
  492.     NULL,
  493.     &NameGad,        /* Controls */
  494.     INITFROMDATA | STOREDATA,        /* Flags */
  495.     NULL,        /* RequestTags */
  496.     NULL,        /* Borders */
  497.     NULL,        /* Images */
  498.     NULL,        /* ITexts */
  499.     NULL,        /* InitFunc */
  500.     0,
  501.     NULL,
  502.     NULL,        /* DataStruct */
  503.     NULL,        /* EndFunction */
  504.     NULL,        /* LoopFunction */
  505.     0,0,        /* CallLoop, LoopBitsUsed */
  506.     0,0,        /* AdditionalSignals, SignalFunction */
  507.     NULL,        /* LocalMsgClassList */
  508.     NULL,        /* LocalPKindCassList */
  509.     NULL,        /* MsgHandlerList */
  510.     NULL,
  511.     NULL,
  512.     NULL,
  513.     NULL,
  514.     NULL,
  515.     NULL,
  516.     NULL,
  517.     NULL,
  518.     NULL
  519. };
  520.  
  521. /* Current line is 519 (in title bar above) */
  522. /* End of IntuiGen generated code */
  523.  
  524. BOOL NewCard ()
  525. {
  526.     struct Person *new;
  527.  
  528.     new=(void *)AllocRemember(&CardKey,sizeof(struct Person), MEMF_PUBLIC | MEMF_CLEAR);
  529.     if (!new) return (1);
  530.     if (OnScreen->Next) OnScreen->Next->Prev=new;
  531.     new->Next=OnScreen->Next;
  532.     new->Prev=OnScreen;
  533.     OnScreen->Next=new;
  534.     OnScreen=new;
  535.     return (0);
  536. }
  537.  
  538. /* The Preceding function allocates memory for a new "Card" and adds it
  539.     to the linked list of cards */
  540.  
  541. main ()
  542. {
  543.     IntuitionBase=OpenLibrary("intuition.library",36);
  544.     GfxBase=OpenLibrary ("graphics.library",0);
  545.     GadToolsBase=OpenLibrary("gadtools.library",0);
  546.  
  547.     if (!IntuitionBase || !GfxBase) goto done;
  548.  
  549.     CardRequest.Window=OpenWindowTagList (NULL,CardRequest.NewWindowTags);
  550.     if (!(CardRequest.Window)) goto done;
  551.  
  552.     OnScreen=&CardBase;
  553.     NewCard ();
  554.  
  555.     while (1) {
  556.     CardRequest.DataStruct=(APTR)OnScreen;
  557.     GTRequest (&CardRequest);
  558.     if (!(CardRequest.Terminate)) break; /* If there is an error, break */
  559.     else {
  560.         if (CardRequest.EndControl==&NewGad) NewCard ();
  561.         else if (CardRequest.EndControl==&NextGad && OnScreen->Next)
  562.         OnScreen=OnScreen->Next;
  563.         else if (CardRequest.EndControl==&PreviousGad && OnScreen->Prev!=&CardBase)
  564.         OnScreen=OnScreen->Prev;
  565.         else if (CardRequest.EndControl==&QuitGad) break;
  566.     }
  567.     }
  568. done:
  569.     if (IntuitionBase) {
  570.     FreeRemember (&CardKey,1);
  571.     if (CardRequest.Window) CloseWindow (CardRequest.Window);
  572.     CloseLibrary(IntuitionBase);
  573.     }
  574.     if (GfxBase) CloseLibrary(GfxBase);
  575.     if (GadToolsBase) CloseLibrary(GadToolsBase);
  576. }
  577.  
  578. /* This function (which is where the program will start) initializes
  579.    the global variables, handles the display of different cards,
  580.    Calls NewCard to add additional cards to the linked list when
  581.    necessary, and calls GTRequest.  GTRequest is part of the IntuiGen
  582.    link time library code (These libraries could easily be made into system
  583.    run time libraries) and handles all the details of the Intuition user
  584.    interface using the data stored in the IntuiGen structures generated
  585.    above (by IntuiGen). This makes implementing something simple like a
  586.    card file, truly simple as the user interface worries are already
  587.    accounted for.
  588. */
  589.  
  590.  
  591. /* Current line is 589.  This means that the above inserted code is 70 lines
  592.     long.
  593. */
  594.  
  595. /* the program is now ready to compile */
  596.  
  597.